package gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;

/**
 * Tab class for JTabbedPane in PictureFrame class. 
 * Allows for tabs to be closed using close button in this component
 * 
 * @author Troy Ferrell
 */
public class PictureTab extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	private static final int CLOSE_ICON_SIZE = 20;
	private static final String CLOSE_ICON_PATH = "src//resources//x_icon.png";
	private final PictureFrame myPicFrame;
	
	public PictureTab(final PictureFrame frame, String name)
	{
		myPicFrame = frame;
		
		this.setOpaque(false);
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		JButton closeButton = new JButton(new ImageIcon(CLOSE_ICON_PATH));
		closeButton.setPreferredSize(new Dimension(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE));
		closeButton.addActionListener(this);
		closeButton.setBorder(new EmptyBorder(5,5,5,5));
	
		add(new JLabel(name));
		add(closeButton);
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		myPicFrame.removeTab(this);
	}
	
}
